﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_PersonalDDetail
    {
        public static void GetPday(string u_id,System.Web.UI.HtmlControls.HtmlAnchor a1,string name)
        {
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Configuration_main where userID=" + u_id + " ");
            if (ds.Tables[0].Rows.Count > 0)
            {
                a1.InnerHtml = name + "有" + ds.Tables[0].Rows.Count + "天未完成工作";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    a1.InnerHtml += "(<a>" + Convert.ToDateTime(ds.Tables[0].Rows[i]["createTime"]).ToString("yyyy-MM-dd") + ")<a>&nbsp;&nbsp;";
                }
            }
        }

        public static void GetListBasis(string u_id, string wheretime, Repeater Repeater1, System.Web.UI.HtmlControls.HtmlAnchor txtallnum1,System.Web.UI.HtmlControls.HtmlAnchor A2)
        {
            DataSet ds1 = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Configuration where userID=" + u_id + " " + wheretime + "  and (Other1 ='1' or Actual_Number >0) order by Other1 desc , Actual_Goal desc");
            if (ds1.Tables.Count > 0)
            {
                Repeater1.DataSource = ds1.Tables[0];
                Repeater1.DataBind();
                int total = 0;
                decimal point = 0;
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    foreach (RepeaterItem Item in Repeater1.Items)
                    {
                        HiddenField hidid = (HiddenField)Item.FindControl("hidid");
                                                                                                                                               if (ds1.Tables[0].Rows[i]["BasisCode"].ToString() == hidid.Value)
                        {
                            if (ds1.Tables[0].Rows[i]["Other1"].ToString() == "1")
                            {
                                                                                                                               
                                                                                                point += Convert.ToDecimal(ds1.Tables[0].Rows[i]["SinglePoint"].ToString());
                            }
                            total += int.Parse(ds1.Tables[0].Rows[i]["Actual_Goal"].ToString());
                        }

                    }
                }
                A2.InnerHtml = point.ToString();
                txtallnum1.InnerHtml = total.ToString();            }
            
        }

                                        public static void GetListBasis(string wheretime, string u_id, Repeater Repeater1, System.Web.UI.HtmlControls.HtmlAnchor txtallnum1, System.Web.UI.HtmlControls.HtmlAnchor a1, string name, System.Web.UI.HtmlControls.HtmlAnchor A2)
        {
            ZLDC.Topo.BLL.Estate.lp_PersonalDDetail.GetListBasis(u_id, wheretime, Repeater1, txtallnum1,A2);
            ZLDC.Topo.BLL.Estate.lp_PersonalDDetail.GetPday(u_id, a1, name);
        }


                                                  public static string GetUnit(object obj,DataSet ds)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i]["TypeCode"].ToString() == obj.ToString())
                {
                    return ds.Tables[0].Rows[i]["Unit"].ToString();
                }
            }
            return obj.ToString();
        }

                                                public static string GetHighest(object obj,DataSet ds)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (ds.Tables[0].Rows[i]["TypeCode"].ToString() == obj.ToString())
                {
                    return ds.Tables[0].Rows[i]["Highest"].ToString();
                }
            }
            return obj.ToString();
        }
                                                                        public static void GetRemark(TextBox txtRemark, string deptid,string u_id,string txtTime,Button btn)
        {
            string sql = "select remark from lp_Configuration_main where workDay='"+Convert.ToDateTime(txtTime).ToString("yyyy-MM-dd")+"' and userID="+u_id+" ";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0][0].ToString() != "" || _Utility.GetInfoBySession().m_sStation!="分行经理")
                    {
                        btn.Enabled = false;
                        txtRemark.Text = ds.Tables[0].Rows[0][0].ToString();
                    }
                }
            }
        }

                                public static void UpdateRemark(Page p,TextBox txtRemark,string u_id,string txtTime,int mainid)
        {
            string sql = "update lp_Configuration_main set updateTime='"+DateTime.Now+"',updateUser="+_Utility.GetInfoBySession().m_sUserID+", remark='"+txtRemark.Text+"' where id="+mainid+"";
            int i = ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);
            if (i > 0)
            {
                p.Response.Write("<script>window.location.href=location.href;</script>");
            }
        }

        public static void UpdateisConfirm(Page p, string u_id, string time)
        {
            string sql = "update lp_Configuration_main set isConfirm=1 where userid=" + u_id + " and workday='" + Convert.ToDateTime(time).ToString("yyyy-MM-dd") + "'";
            int i = ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);

            p.Response.Write("<script>parent.document.getElementById('txtTime').value = '" + time + "';parent.document.getElementById('btnxx').click();</script>");
            
        }
    }
}
